package org.example.chessboard;

import org.example.chessboard.model.Point;
import org.example.chessboard.util.ChessboardPathFinder;

import java.util.List;

public class ChessboardTest {
    public static void main(String[] args) {
        // 定义棋盘：0=空格，1=障碍物
        int[][] board = {
                {0, 0, 1, 0, 0},
                {1, 0, 1, 1, 0},
                {0, 0, 0, 1, 0},
                {0, 1, 1, 0, 0},
                {0, 0, 0, 0, 1}
        };

        ChessboardPathFinder finder = new ChessboardPathFinder(board);

        // 测试1：两点间最优路径
        Point start = new Point(0, 0);
        Point end = new Point(4, 2);
        List<Point> path = finder.findShortestPath(start, end);

        System.out.println("从" + start + "到" + end + "的最优路径：");
        if (path.isEmpty()) {
            System.out.println("无有效路径");
        } else {
            for (Point p : path) {
                System.out.print(p + " → ");
            }
            System.out.println("终点");
            System.out.println("路径长度：" + (path.size() - 1));
        }

        // 测试2：查找最近空格
        Point target = new Point(1, 3);  // 该点是障碍物(1)
        Point nearest = finder.findNearestEmpty(target);
        System.out.println("\n目标点" + target + "最近的空格：" + nearest);

        // 测试3：目标点本身是空格
        Point target2 = new Point(2, 0);
        Point nearest2 = finder.findNearestEmpty(target2);
        System.out.println("目标点" + target2 + "最近的空格：" + nearest2);
    }
}
